﻿Imports App_Code
Imports DQDataTypes = App_Code.DQDataTypes
Imports IUIBuildingBlock = App_Code.IUiBuildingBlock
Partial Class DQOptionQuestion
    Inherits System.Web.UI.UserControl
    Implements IUIBuildingBlock
    Private Shared HotDeal As App_Code.HotDeal

    Public ReadOnly Property DataType() As DQDataTypes Implements IUIBuildingBlock.DataType
        Get
            Return DQDataTypes.Option
        End Get
    End Property

    Public Property QuestionId() As Integer Implements IUIBuildingBlock.QuestionId
        Get
            Return CType(dqQuestionId.Value, Integer)
        End Get
        Set(ByVal value As Integer)
            dqQuestionId.Value = CType(value, String)
        End Set
    End Property

    Public Property Answer() As Object Implements IUIBuildingBlock.Answer
        Get
            Return dqAnswer.SelectedValue
        End Get
        Set(ByVal Value As Object)
            dqAnswer.SelectedValue = Value
        End Set
    End Property

    Public Property QuestionText() As String Implements IUIBuildingBlock.QuestionText
        Get
            Return dqQuestion.Text
        End Get
        Set(ByVal Value As String)
            dqQuestion.Text = Value
        End Set
    End Property

    Protected Sub PageLoad(sender As Object, e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack Then Exit Sub
        'Dim questionId = Session("questionId")
        'Dim questionId As Integer = questionId()
        'TODO: Load Option by QuestionID
        Dim clsHotDeal As New HotDeal()
        Dim lstOptions = clsHotDeal.GetOptionByQuestionId(QuestionId()) 'questionId

        BindSelect(lstOptions)
    End Sub

    Private Sub BindSelect(lstOptions As Object)
        dqAnswer.DataSource = lstOptions
        dqAnswer.DataValueField = "Value"
        dqAnswer.DataTextField = "Text"
        dqAnswer.DataBind()
    End Sub
End Class
